home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / SHOWREC.C < prev    next >
C/C++ Source or Header  |  1995-05-23  |  7KB  |  240 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    showrec.c
  5. //   Title:    Application Template
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains the program entry point for
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <dio.h>
  41.  
  42.  
  43. //----------------------------------------------------------------------------
  44. //    Stack size
  45. //----------------------------------------------------------------------------
  46. #if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
  47. unsigned _stklen = 0x4000;
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //    Globals
  53. //----------------------------------------------------------------------------
  54.  
  55. //
  56. // A useless string which is simply embedded in the executable.
  57. //
  58. PSZ __pszCredits__ = "Written by John M Weeder, 1993";
  59.  
  60.  
  61. //
  62. //    This should contain a program description which will be displayed as
  63. //    part of the program's help text.
  64. //
  65. static PCSZ pcszDescription =
  66.     "This program displays the contents of a stripped fixed length data file.";
  67.  
  68. //
  69. //    Program command line options
  70. //
  71. static BOOL fKey = FALSE;
  72. static BOOL fSorted;
  73. static LONG lDuplicates;
  74. static CHAR szConfig[MAX_PATH] = "data";
  75. static CHAR szInput[MAX_PATH];
  76. static LONG lStart = 0;
  77. static LONG lEnd = 0x7FFFFFFFL;
  78. static LONG lLength = -1;
  79. static BS_CMDOPT acmdopt[] =
  80.     {
  81.     { "BEGIN",       (PVOID)&lStart,         CMDOPT_NUMERIC,         "Starting record."},
  82.     { "END",           (PVOID)&lEnd,             CMDOPT_NUMERIC,        "Ending record."},
  83.     { "KEY",           (PVOID)&fKey,             CMDOPT_TRUE,            "Display sort keys."},
  84.     { "LENGTH",       (PVOID)&lLength,        CMDOPT_NUMERIC,        "Number of records to display."},
  85.     { "config",     (PVOID)szConfig,        CMDOPT_FILESPECR(80),"Configuration file name."},
  86.     { "input",         (PVOID)szInput,        CMDOPT_FILESPEC(80), "Input file name."},
  87.     BS_CMDOPT_NULL,
  88.     };
  89.  
  90.  
  91. //----------------------------------------------------------------------------
  92. //   Description:    Call back function to display a record
  93. //    Parameters:    pdlmrec        Record data.
  94. //       Returns:    0
  95. //----------------------------------------------------------------------------
  96. static SHORT FN_E ShowRec(PDLMREC pdlmrec)
  97. {
  98. static CHAR szKey[2][MAX_RECORD_LEN+1];
  99. static SIZET cWhich;
  100. static SIZET cKeyLen;
  101.     SIZET i, j;
  102.  
  103.     if (pdlmrec->lId < 0)                    // Initialization/termination codes
  104.         {
  105.         if (pdlmrec->lId == DAI_INITIALIZE)
  106.             {
  107.             pdlmrec->pcfg->lNoise = 0;
  108.             memset(szKey, 0, sizeof(szKey));
  109.             cKeyLen = DataKeyLen(pdlmrec->pcfg);
  110.             cWhich = 0;
  111.             fSorted = TRUE;
  112.             lDuplicates = 0;
  113.             }
  114.         else if (fKey && pdlmrec->pcfg->fVerbose)
  115.             {
  116.             if (fSorted)
  117.                 Output("File is sorted.\n");
  118.             else
  119.                 Output("File is NOT sorted.\n");
  120.             Output("%ld duplicate keys.\n", lDuplicates);
  121.             }
  122.         return 0;
  123.         }
  124.  
  125.     if (fKey)
  126.         {
  127.         CHAR ch = ' ';
  128.         SIZET i;
  129.  
  130.  
  131.         DataKey(pdlmrec, szKey[cWhich]);
  132.         if (pdlmrec->lId)
  133.             {
  134.             int retval = memcmp(szKey[!cWhich], szKey[cWhich], cKeyLen);
  135.            if (retval > 0)
  136.                 {
  137.                 fSorted = FALSE;
  138.                 ch = '*';
  139.                 }
  140.             else if (retval == 0)
  141.                 {
  142.                 lDuplicates++;
  143.                 ch = '=';
  144.                 }
  145.             }
  146.         if (pdlmrec->pcfg->fVerbose)
  147.             {
  148.             Output("%c%08ld|%08lX:%04hX  ",
  149.                 ch,
  150.                 pdlmrec->lId,
  151.                 pdlmrec->recid.lBlock,
  152.                 pdlmrec->recid.usOffset);
  153.  
  154.             for (i = 0; i < MIN(16, cKeyLen); ++i)
  155.                 if (isascii(szKey[cWhich][i]) && isprint(szKey[cWhich][i]))
  156.                     Output("%c", szKey[cWhich][i]);
  157.                 else
  158.                     Output(" ");
  159.  
  160.             Output("  ");
  161.             for (i = 0; i < MIN(16, cKeyLen); ++i)
  162.                 Output("%02lX", (ULONG)(BYTE)szKey[cWhich][i]);
  163.             Output("\n");
  164.             }
  165.         cWhich = !cWhich;
  166.         }
  167.     else
  168.         {
  169.         Output("Record=%8ld  Offset=%8ld  Size=%4ld  XRef=%08lX:%04hX\n",
  170.             pdlmrec->lId,
  171.             (LONG)pdlmrec->pdlmndx->fpos,
  172.             (LONG)pdlmrec->pdlmndx->usLen,
  173.             pdlmrec->recid.lBlock,
  174.             pdlmrec->recid.usOffset);
  175.  
  176.         for (i = 0; i < pdlmrec->pcfg->cFields; ++i)
  177.             if (BTEST(pdlmrec->pcfg->afld[i].fs, FLD_FIXED))
  178.                 {
  179.                 SIZET cLen = pdlmrec->pcfg->afld[i].cLen;
  180.                 PSZ psz = pdlmrec->apsz[i];
  181.  
  182.                 Output(" %20.20s: '", pdlmrec->pcfg->afld[i].szName);
  183.  
  184.                 for (j = 0; j < MIN(16, cLen); ++j)
  185.                     if (isascii(psz[j]) && isprint(psz[j]))
  186.                         Output("%c", psz[j]);
  187.                     else
  188.                         Output(" ");
  189.  
  190.                 Output("'  ");
  191.                 for (j = 0; j < MIN(16, cLen); ++j)
  192.                     Output("%02lX", (ULONG)(BYTE)psz[j]);
  193.  
  194.                 Output("\n");
  195.                 }
  196.             else
  197.                 {
  198.                 Output(" %20.20s: '%.40s'\n",
  199.                     pdlmrec->pcfg->afld[i].szName,
  200.                     pdlmrec->apsz[i]);
  201.                 }
  202.         }
  203.     return 0;
  204. }
  205.  
  206.  
  207. //----------------------------------------------------------------------------
  208. //   Description:    main() - Program entry point
  209. //    Parameters:    Standard C parameters
  210. //       Returns:    DOS return code.
  211. //----------------------------------------------------------------------------
  212. int main(int argc, char **argv)
  213. {
  214. static BS_CFG cfg = CFG_DFT;
  215. static DATACFG dcfg;
  216.  
  217.     //
  218.     //    Initialize base library
  219.     //
  220.     BaseLibraryInitialize(argc, argv, &cfg);
  221.     BaseTitle("$Revision:  93.1  $", __DATE__, __TIME__, "Display Stripped Data Files");
  222.     if (!BaseTitleHelp(acmdopt, pcszDescription))
  223.         return 99;
  224.  
  225.     if (!DataConfigRead(szConfig, &dcfg))
  226.         {
  227.         Output("Failed reading configuration file.\n");
  228.         return 99;
  229.         }
  230.     if (szInput[0])
  231.         if (!DataConfigFiles(&dcfg, szInput))
  232.             return 99;
  233.     if (lLength > 0)
  234.         lEnd = lStart + lLength - 1;
  235.     return DataProcess(&dcfg, lStart, lEnd, ShowRec) ? 0: 99;
  236. }
  237. //----------------------------------------------------------------------------
  238. //------------------------------- End of File --------------------------------
  239. //----------------------------------------------------------------------------
  240.